package net.stuffrepos.bricknetcenter.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public class TimedLoopingThread extends LoopingThread {

    private final Runnable runnable;
    private final long sleepTime;
    private static final Log log = LogFactory.getLog(TimedLoopingThread.class);

    public TimedLoopingThread(long sleepTime, Runnable runnable) {
        this.runnable = runnable;
        this.sleepTime = sleepTime;
    }

    @Override
    public void loopingRun() {
        try {
            this.runnable.run();
            sleep(sleepTime);
        } catch (Exception ex) {
            log.warn("Exception on ThreadTimer looping", ex);
        }
    }
}
